// So beautiful.
// $$
// C_a^b = C_{a-1}^{b-1} + C_{a-1}^b
// $$
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 9;
const int MOD = 1e9 + 7;
int f[maxn][maxn];
int main() {
  for (int i = 0; i <= 2000; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (!j)
        f[i][j] = 1;
      else
        f[i][j] = (f[i - 1][j - 1] + f[i - 1][j]) % MOD;
    }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    cout << f[a][b] << '\n';
  }
}
